package site.marqstree.kotlin.library.good.ui.activity.goodlist.presenter

import site.marqstree.kotlin.library.base.data.net.observer.RxObserver
import site.marqstree.kotlin.library.base.data.net.request.RxRequest
import site.marqstree.kotlin.library.base.extent.json2Bean
import site.marqstree.kotlin.library.base.presenter.view.BasePresenter
import site.marqstree.kotlin.library.good.ui.activity.goodlist.bean.GoodPageBean
import site.marqstree.kotlin.library.good.ui.activity.goodlist.view.GoodListView
import site.marqstree.kotlin.provider.common.ProviderConstant
import javax.inject.Inject


/*
 * 项目名: KotlinMall
 * 包名: site.marqstree.kotlin.library.good.ui.fragment.category.centent.presenter
 * 文件名: ContentPresenter
 * 创建者: marqstree
 * 创建时间: 2020/3/7 11:58
 * 描述: TODO
 */
class GoodListPresenter @Inject constructor():BasePresenter<GoodListView>(){

    fun getGoodList(brandId: Int,pageIndex: Int){

        RxRequest.builder()
            .setUrl(ProviderConstant.GOOD_LIST_BY_BRANDID_URL)
            .setParam("brandid",brandId)
            .setParam("pageindex",pageIndex)
            .get()
            .json2Bean(GoodPageBean::class.java)
            .subscribe(object :RxObserver<GoodPageBean>(){
                override fun onNext(data: GoodPageBean) {
                    mView.onGoodListResult(data)
                }
            })
    }

    fun getGoodList(keyword: String,pageIndex: Int){
        RxRequest.builder()
            .setUrl(ProviderConstant.GOOD_LIST_BY_KEYWORD_URL)
            .setParam("keyword",keyword)
            .setParam("pageindex",pageIndex)
            .get()
            .json2Bean(GoodPageBean::class.java)
            .subscribe(object :RxObserver<GoodPageBean>(){
                override fun onNext(data: GoodPageBean) {
                    mView.onGoodListResult(data)
                }
            })
    }
}